package cc.lucien.web.controller;

import cc.lucien.web.entity.Goods;
import cc.lucien.web.entity.GoodsType;
import cc.lucien.web.service.GoodsService;
import cc.lucien.web.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/mall")
public class MallController {

    @Autowired
    GoodsService goodsService;

    @Autowired
    GoodsTypeService goodsTypeService;

    // 去到主页
    @RequestMapping("/index")
    public String index(Map<String, Object> map){
        // 拿商品类型
        List<GoodsType> goodsTypeList = goodsTypeService.selectAllGoodsTypes();
        // 拿商品数据，默认拿所有已上架数据
        List<Goods> goodsList =  goodsService.selectGoodsStatusAs1();
        map.put("goodsTypeList", goodsTypeList);
        map.put("goodsList", goodsList);
        return "mall/index";
    }

    // 分类查询
    @RequestMapping("/getGoodsByType/{id}")
    public String getGoodsByType(@PathVariable Integer id, Map<String, Object> map) {
        // 拿商品类型
        List<GoodsType> goodsTypeList = goodsTypeService.selectAllGoodsTypes();
        // 根据类型拿商品数据
        List<Goods> goodsList = goodsService.selectGoodsByType(id);
        map.put("goodsTypeList", goodsTypeList);
        map.put("goodsList", goodsList);
        return "mall/index";
    }


}
